Skip to content

fix(plugins): improve installation errors and update reliability - #2176

Merged
liukewia merged 11 commits into
TencentCloud:developfrom
ideshun:fix/plugin-install-failure-experience
Nov 24, 2026
Merged

liukewia merged 11 commits into
TencentCloud:developfrom
ideshun:fix/plugin-install-failure-experience

Conversation

@ideshun

@ideshun ideshun commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Improve plugin installation error reporting and update reliability. Standard requests, uploads, and installation SSE preserve Octop's structured errors and translations. HTML and other non-JSON error responses show a concise HTTP status and request ID instead of the response body. Error reads are bounded to 16 KiB and 2 seconds, including the 503 setup probe.

Prepare downloads, extraction, and pip installation in background workers; keep plugin registration and runtime refresh on the event loop. Downloads have a 15-second socket timeout, a 120-second total budget, a 64 MiB archive limit, and a 256 MiB extraction limit. Serialize installation of the same plugin, reject conflicts before running pip, and wait for worker cleanup on cancellation. Failed forced updates restore the previous directory, modules, and registration. Disabled plugins remain disabled, and a failed directory rename preserves the existing registration.

Changes made by pip to the shared Python environment cannot be rolled back transactionally. Recovery in this PR covers plugin files, modules, and registration.

Target branch

  • Base is develop

Type of change

  • Bug fix

Test plan

  • New installation reliability and download boundary regressions: 10 passed, covering worker execution, cancellation locks, conflicts, pip failures, rename failures, and updates to disabled plugins.
  • Frontend authentication, setup, mobile, and error regressions: 21 passed. Additional setup/error tests: 9 passed; these sets overlap and are not additive.
  • Backend installation-related test group: 37 passed, 2 warnings.
  • Final frontend production build succeeded (9,419 modules). Mypy passed for the three modified backend source files.
  • Repository-wide Ruff and formatting checks passed (1,241 files).
  • Reproduced lost registration after failed updates and unintended loading of disabled plugins against an independent upstream worktree. Tests of newly introduced interfaces are not claimed as pre-fix behavioral reproductions.
  • Linux and Windows CI for the final head: pending verification.
  • Frontend lint reports 3 errors and 70 warnings. Normalized full output matches an independent develop baseline; no additional lint findings were introduced.

Checklist

  • Updated CHANGELOG.md
  • Single purpose: plugin installation error reporting and reliability
  • Reviewed scope, cancellation, concurrency, and failure recovery
  • UI screenshots / feature demo: no production screenshots attached; validation above uses local regression tests.
image

Before

image

After

image

The earlier workspace loss has now been reproduced safely: CLI cleanup tests replace Path.home() but inherit OCTOP_HOME, so clean --all --yes targets the real Octop data directory. A local audit guard blocked recursive deletion and captured its stack. Development, disposable test checkout, and source archives are kept separately. No deployment or production configuration changes were made.

CI repair: marketplace configuration persistence

Marketplace installs now persist the effective enabled state inside the existing installation transaction. Forced updates preserve disabled state. If configuration persistence fails, the old directory and plugin registration are restored. Added regressions cover preservation of unrelated settings and corrupt-config rollback for fresh installs and updates.

Current repair validation:

  • Before the fix: both original CI failures reproduced with config.json FileNotFoundError.
  • After the fix: 67 focused backend tests passed; 13 frontend tests passed.
  • Repository Ruff checks and formatting checks passed; full mypy passed for 597 source files.
  • Inherited OCTOP_HOME reproduced all six failures in tests/unit/cli/test_cli_db.py: bootstrap refuses the real nonempty data directory. The guarded cleanup test also attempted to delete the real OCTOP_HOME. Clean-environment cleanup tests passed (3 tests); cleanup, offline DB and CLI stub regressions passed together (12 tests). These explain local environment hazards; the exact six markers in the old truncated nonverbose log cannot be mapped conclusively.
  • Full local make all is not claimed green. Full-suite maxfail=1 diagnostics were stopped after collection/initial integration tests once destructive environment leakage was established. The pre-commit gate is bypassed for this repair under explicit user authorization to avoid running tests in the development checkout; isolated CI remains the full Linux/Windows verification.
  • PR remains draft pending checks for the pushed repair head.

@ideshun ideshun changed the title fix(plugins): 改善插件安装失败提示与更新可靠性 fix(plugins): improve installation errors and update reliability Oct 18, 2026
@ideshun
ideshun marked this pull request as ready for review October 19, 2026 06:48
@seed30

seed30 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

感谢本 PR 在插件安装事务性、回滚、路径穿越修复、下载预算和前端错误有界读取方面的改进,方向很好。合入前有两个回归需要修复。

基于提交:54436b5a

阻塞 1:reload 接口丢失逐插件错误隔离

  • 位置:src/octop/api/routers/plugins.py 第 117–118 行调用 mgr.prepare_reload();src/octop/infra/agents/plugins/manager.py 第 184–192 行的 prepare_reload 没有异常捕获。
  • 旧行为:load_installed(manager.py 第 478–508 行)对每个插件单独 try/except,损坏的插件只记日志,其他插件照常加载。
  • 新行为:prepare_reload 对所有已启用插件调用 install_dependencies,任一插件失败都会中断整个循环,且 PluginManifest.load 也不在 try 中。
  • 复现:在隔离环境中放入一个 plugin.yaml 损坏的插件和一个正常的 echo-tool。prepare_reload() 抛出 ParserError;旧路径 load_installed() 跳过损坏插件,仍加载 echo-tool。
  • 影响:任一已启用插件清单损坏,或依赖安装失败,都会导致整个 reload 失败,所有插件都无法重新加载。
  • 建议:prepare_reload 对每个目录独立 try/except,记录日志后继续,与 load_installed 保持一致。同时补充覆盖 reload 路径的测试,当前 PR 的测试没有覆盖这一路径。

阻塞 2:服务重启的错误分类失效

  • 位置:dashboard/src/hooks/useServiceRestart.ts 第 26–35 行的 shouldPollAfterRestartError,关键判断在第 31–32 行。
  • 原因:本 PR 将 request() 的错误消息改为服务端 message 或 HTTP <status>(见 dashboard/src/api/responseError.ts),不再以 Request failed: 开头。于是 msg.startsWith("Request failed:") 为假,函数直接返回 true。
  • 影响:updateApi.restartService(dashboard/src/api/modules/update.ts 第 65–66 行)返回的 403、409 等 4xx 错误会进入最长 120 秒的轮询(RESTART_POLL_TIMEOUT),最后显示超时,用户看不到真实原因。
  • 建议:改用 ApiResponseError.status 判断,仅 502/503/504 才轮询。同时补充单元测试。useServiceRestart.test.ts 目前只测试了 hasProcessRestarted。

建议合入前处理 3:zip 解压大小限制可被伪造

  • 位置:src/octop/infra/agents/plugins/manager.py 第 801–815 行。
  • 问题:大小检查依据 ZipInfo.file_size,这是中央目录中的声明值,可被伪造。随后的 zf.extractall() 实际写入量不受限制,这一限制无法防御 zip 炸弹。
  • 建议:逐成员流式解压,并累计实际写入字节数。成员数量上限(10000)已存在,可保留。

建议合入前处理 4:requires 作为 pip 参数存在注入风险

  • 位置:src/octop/infra/agents/plugins/installation.py 第 42–43 行。
  • 问题:manifest 的 requires 条目直接传给 pip。以 - 开头的条目会被当作选项解析,例如 --index-url 可改变包源。
  • 建议:拒绝以 - 开头的条目,并校验为合法的 requirement 格式。

后续处理 5:install_url 的 SSRF 风险(本 PR 未引入)

  • 位置:src/octop/infra/agents/plugins/manager.py 第 138–144 行的 _assert_http_url。
  • 问题:只校验协议,不校验目标地址,重定向后的内网地址也不做限制。
  • 建议:按项目安全规则,拒绝内网地址,并额外拦截 9.*、10.*、11.*、21.*、30.*,以及 127.*、172.16.*–172.31.*、192.168.*、169.254.*。如确需访问内网,应先与用户确认。本 PR 重写了下载函数,可顺便处理。

测试

  • 在隔离副本中运行 test_plugin_install_reliability.py、test_plugin_download_limits.py、test_plugin_manager.py、test_clean_cmd.py,共 34 项通过。
  • 前端测试未在本地运行。
  • 未覆盖的场景:reload 错误隔离、重启错误分类、zip 实际解压量限制、requires 参数校验。

其他

  • PR 描述称 Linux 与 Windows CI 仍待验证。描述中的 “PR remains draft pending checks” 与时间线中的 “marked as ready for review” 不一致,请以 Checks 页面为准,并同步更新描述。

合入建议

  • 修复阻塞 1 和阻塞 2,并补充对应测试后可以合入。
  • 问题 3 和 4 建议合入前处理。
  • 问题 5 可以后续跟进。

@liukewia

Copy link
Copy Markdown
Collaborator

当前 CI 虽然全绿,但代码审查发现:

插件依赖安装可能在服务环境失败
src/octop/infra/agents/plugins/installation.py:55-67 只用 shutil.which("uv"),找不到 uv 就直接执行 python -m pip。但 uv 环境可能没有 pip,且没有复用已有的 runtime_packages 安装逻辑,导致插件安装失败。不同插件并发安装还可能同时修改同一个 Python 环境。

requirements.txt 绕过了新增的参数校验
installation.py:41-43 直接执行 pip install -r requirements.txt,文件内部仍可包含 --index-url、--trusted-host、-e 等 pip 参数。PR 只校验了 manifest 里的 requires,校验不完整。

前端 404 / 503 判断出现回归
ApiResponseError 把状态码放到了 .status,但以下代码仍只检查 error.message:

dashboard/src/utils/apiError.ts:59-64:部分 404 不再被识别为 Not Found。
ProviderConfigModal.tsx:208-211:Ollama 返回 503 但 message 不含 503 时,不会进入不可用状态。
另外还有两个次要问题:

requestUpload 超过 16 KiB 时直接抛普通 Error,丢失 request ID 和结构化错误:dashboard/src/api/request.ts:661-665。
解压实际仍被旧的 _MAX_PLUGIN_UNCOMPRESSED_BYTES = 64 MiB 限制,和 PR 声称的 256 MiB 不一致:manager.py:64,1098。
所以结论是:技术上 GitHub 显示可合,但代码层面还有至少 3 个应先修复的回归/阻塞项。

@liukewia

liukewia commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

PR 2176 最新修改把之前的问题基本修好了,但​仍有一个 P2 回滚问题,建议修复后再合并​。

强制更新已有插件时,如果旧目录因权限或文件占用而重命名失败,这里的操作尚未成功,异常回滚却会执行 delete_owner,删除数据库里的原插件文件。此时本地目录还在,看起来可能正常,但其他节点同步或重建缓存时会丢失插件。

建议区分「原本没有插件」与「旧插件尚未成功移动」,未发生修改时不要清理数据库;补一个挂载真实 ControlFileRepo、模拟重命名失败的测试。现有测试只检查本地注册保留,覆盖不到这个问题。

@liukewia
liukewia merged commit 625c1a7 into TencentCloud:develop Nov 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants